package orgs.example.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import orgs.example.mapper.CustomerMapper;
import orgs.example.mapper.StaffMapper;
import orgs.example.pojo.Cancellation;
import orgs.example.pojo.MeetingRoom;
import orgs.example.pojo.Reservation;
import orgs.example.service.StaffService;
import orgs.example.utils.ThreadLocalUtil;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class StaffServiceImpl implements StaffService {

    @Autowired
    private StaffMapper staffMapper;

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public List<Cancellation> searchAllCancellation() {
        return staffMapper.searchAllCancellation();
    }

    @Override
    public Reservation searchReserveByreserveId(Integer reserveId) {
        return staffMapper.searchReserveByreserveId(reserveId);

    }

    @Override
    public List<Reservation> searchAllReservation() {
        return staffMapper.searchAllReservation();
    }

    @Override
    public void changeRoomStatus(Integer roomid, String status) {
        staffMapper.changeRoomStatus(roomid,status);
    }

    @Override
    public List<MeetingRoom> searchAllRoom() {
        return staffMapper.searchAllRoom();
    }

    @Override
    public Cancellation searchCancellationByCancellationId(Integer cancelId) {
        return staffMapper.searchCancellationByCancellationId(cancelId);
    }

    @Override
    public void changCancellationStatus(Integer cancelId, String cancelStatus) {
        staffMapper.changCancellationStatus(cancelId,cancelStatus);
    }

    @Override
    public void changeReservationStatus(Integer reserveId, String reserveStatus) {
        customerMapper.changeReservationStatus(reserveId,reserveStatus);
    }

    @Override
    public MeetingRoom searchRoomByRoomId(Integer roomId) {
        return customerMapper.searchRoomByRoomId(roomId);
    }

    @Override
    public void changCancellationProcessBycancelId(Integer cancelId) {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("userId");

        Date now = new Date();

        staffMapper.changCancellationProcessBycancelId(cancelId,id,now);
    }
}
